﻿<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员统计</h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>会员统计</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="box ordersetting">


                <div class="block">
                    <span class="demonstration">日期</span>
                    <el-date-picker
                            v-model="range"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-formart="yyyy-MM-dd"
                            :picker-options="pickerOptions">
                    </el-date-picker>


                    <span class="demonstration">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;统计类型</span>
                    <el-select v-model="value" placeholder="请选择" @change="getValue">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </div>

                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="main" style="height:450px;"></div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>

<script>
    new Vue({
        el: '#app',
        data: {
            range: "",
            pickerOptions: {
                shortcuts: [{
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                },{
                    text: '去年至今',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            options: [{
                value: '1',
                label: '新增会员'
            }, {
                value: '2',
                label: '预约人数'
            }, {
                value: '3',
                label: '报告上传'
            }],
            value: ''
        },

        methods: {
            getData1(res) {
                var myChart = echarts.init(document.getElementById('main'));
                var option = {
                    title: {
                        text: '会员数量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['会员数量']
                    },
                    xAxis: {
                        data: res.data.data.months
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '会员数量',
                        type: 'line',
                        data: res.data.data.memberCount
                    }]
                };
                myChart.setOption(option);
            },
            getData2(res) {
                var myChart = echarts.init(document.getElementById('main'));
                var option = {
                    title: {
                        text: '预约人数'
                    },
                    tooltip: {},
                    legend: {
                        data: ['预约人数']
                    },
                    xAxis: {
                        data: res.data.data.months
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '预约人数',
                        type: 'line',
                        data: res.data.data.orderCount
                    }]
                };
                myChart.setOption(option);
            },
            getData3(res) {
                var myChart = echarts.init(document.getElementById('main'));
                var option = {
                    title: {
                        text: '报告上传数量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['报告上传数量']
                    },
                    xAxis: {
                        data: res.data.data.months
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '报告上传数量',
                        type: 'line',
                        data: res.data.data.physicalCount
                    }]
                };
                myChart.setOption(option);
            },
            //绑定下拉框单击事件
            getValue(val) {
                var startTime = this.range[0];
                var endTime = this.range[1];
                var aa = this.formatDate(startTime.getFullYear(), startTime.getMonth() + 1, startTime.getDate());
                var bb = this.formatDate(endTime.getFullYear(), endTime.getMonth() + 1, endTime.getDate());
                //console.log(val);
                if (val == 1) {
                    axios.post("/member/getMemberCount.do?startTime=" + aa + "&endTime=" + bb).then((res) => {
                        this.getData1(res)
                    });
                }
                if (val == 2) {
                    axios.post("/member/getOrderCount.do?startTime=" + aa + "&endTime=" + bb).then((res) => {
                        this.getData2(res)
                    });
                }
                if (val == 3) {
                    axios.post("/member/getPhysicalCount.do?startTime=" + aa + "&endTime=" + bb).then((res) => {
                        this.getData3(res)
                    });
                }
            },
            formatDate: function (year, month, day) {
                var y = year;
                var m = month;
                if (m < 10) m = "0" + m;
                var d = day;
                if (d < 10) d = "0" + d;
                return y + "-" + m + "-" + d
            }
        }
    });
</script>
</html>
